package com.engine.zzworkflow.web;

import com.engine.zzworkflow.cmd.sendBeCurrentBusinessCmd;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.hrm.User;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.request.RequestManager;
import weaver.workflow.workflow.WorkflowComInfo;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * 用于如果用户没有点生成凭证，那么直接提交，需要这个校验操作
 * 帮助用户直接抛送会计引擎
 */
public class ChenkSendBusinessAction  extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        writeLog("进入方法 WriteBackDatasAction："+requestInfo);
        RequestManager requestManager = requestInfo.getRequestManager();
        String requestid = requestInfo.getRequestid();
        String workflowid = requestInfo.getWorkflowid();
        String nodetype = requestManager.getNodetype();
        String formId = (new WorkflowComInfo()).getFormId(workflowid);
        String tableName = getNameById(formId);
        String lastoperator = requestInfo.getLastoperator();

        RecordSet recordSet = new RecordSet();
        writeLog("workflowid："+workflowid+"，tableName："+tableName+"，requestid："+requestid+"，formId："+formId);
        String sql="select * from "+tableName+" where requestId=?";
        recordSet.executeQuery(sql, new Object[]{requestid});
        if (recordSet.next()) {
            String ljzdm=recordSet.getString("ljzdm");
            if(ljzdm==null || ljzdm.equals("")){
                Map<String,Object> map=new HashMap<>();
                map.put("requestid",requestid);
                map.put("workflowid",workflowid); ;
                map.put("mx",tableName+"_dt1");
                map.put("tablename",tableName);
                map.put("requestid",requestid);
                new sendBeCurrentBusinessCmd(new User(),map);
            }


        }
        return null;
    }
        public static String getNameById(String var0) {
            RecordSet var1 = new RecordSet();
            String var2 = "";
            String var3 = "select tablename from workflow_bill where id=?";
            var1.executeQuery(var3, new Object[]{var0});
            if (var1.next()) {
                var2 = var1.getString("tablename");
            }

            return var2;
        }
}
